<template>
    <div class="leftMenu-wrapper">
        <el-menu class="menu-box" :default-active="defaultActive" router>
            <template v-for="menu in menus">
                <el-menu-item
                        class="menu-item"
                        :key="menu.path"
                        :index="menu.path"
                @click="checkMenu(menu)">
                    <img class="ml20 mr30" :src="activeMenu == menu.path ? menu.activeIcon : menu.icon" alt="">
                    <span slot="title" class="menu-title-first fz16">{{ menu.title }}</span>
                </el-menu-item>
            </template>
        </el-menu>
    </div>
</template>

<script>
    export default {
        name: 'leftMenu',
        props: ['menus', 'currentMenu'],
        data () {
            return {
                defaultActive: '', // 默认激活的菜单的 path
                activeMenu: ''
            }
        },
        created () {
            this.defaultActive = this.currentMenu
            this.activeMenu = this.currentMenu
        },
        beforeRouteEnter (to, from, next) {
            next(vm => {
                vm.defaultActive = to.path
            })
        },
        methods: {
            checkMenu (menu) {
                this.activeMenu = menu.path
            }
        }
    }
</script>

<style scoped lang="scss">
    .leftMenu-wrapper {
        .menu-box {
            border-right: none;
            .menu-item {
                height: 70px;
                line-height: 70px;
                img {
                    width: 22px;
                    height: 22px;
                }
            }
        }
    }
</style>
